﻿@{
    ViewBag.Title = ViewBag.videoname+"-管理集数";
}

 
<div style="padding:10px;">
    <div class="layui-form">
        <a class="layui-btn" href="/Adnn1n/Videomx/Add?videoid=@Request["videoid"]">
            <i class="layui-icon">&#xe608;</i> 添加集数
        </a> 

    </div>
    <table class="layui-table">
        <thead>
            <tr>
                <th>管理</th> 
                <th>创建时间</th> 
                <th>标题</th>
                <th>视频路径</th>
                <th>访问量</th>


            </tr>
        </thead>
        <tbody id="tbody"></tbody>
    </table>
    <div>
        <div style="float: left; line-height: 55px;margin: 0 15px; font-size: 16px;">
            当前共<span id="totalcount"></span>条记录，每页10条，第<span id="pageindex"></span>页/共<span id="pagecount"></span>页
        </div>
        <div id="pages">

        </div>
    </div>
</div>

<script>
var pop_index;

 


    var pagesize = 10; //页大小
    search();
    /*加载第X页数据*/
    function load_blog_data(pageindex) {
      //  console.log("加载第" + pageindex + "页");


        layui.use('layer', function () {
            var $ = layui.jquery, layer = layui.layer;

            $('#pageindex').text(pageindex);


            var postdata = getcond();

            var url = "/Adnn1n/Videomx/List?pageindex=" + pageindex + "&pagesize=" + pagesize;
            pop_index = layer.load(0, {
                shade: [0.3, '#000'] //0.1透明度的白色背景
            });
            $.post(url,postdata, function (json) {
layer.close(pop_index);

                var html = '';
                $.each(json, function (i, item) {
                   // console.log("第" + i + "个元素：");
                  //  console.log(blog);
                    html += '<tr>';
                         html += '    <td>'; 
                    html += '        <a href="javascript:void(0);" onclick="del(' + item.id + ')"><i class="layui-icon">&#x1006;</i> 删除</a>';
                    html += '    </td>'; 
html += '    <td>' + item.createtime + '</td>'; 
html += '    <td>' + item.title + '</td>';
html += '    <td>' + item.videopath + '</td>';
html += '    <td>' + item.visitnum + '</td>';


                    html += '</tr>';

                })

                $('#tbody').html(html);

            }, 'json');
        })


    }

    /*拼接条件返回postdata*/
    function getcond() {

 
        var postdata = { videoid:@Request["videoid"] };
        return postdata;
    }

    /*查询*/
    function search() {

        layui.use(['laypage', 'layer'], function () {
            var laypage = layui.laypage, layer = layui.layer, $ = layui.jquery;

            var postdata = getcond();

            var url = "/Adnn1n/Videomx/GetTotalCount?t=" + new Date().valueOf();
            $.post(url,postdata, function (count) {

                var pagecount = (count % pagesize == 0 ? count / pagesize : Math.ceil(count / pagesize)); //总页数
               // console.log("总记录数：" + count + "，总页数：" + pagecount);
                $('#totalcount').text(count);
                $('#pagecount').text(pagecount);

                laypage({
                    cont: 'pages',
                    pages: pagecount, //得到总页数
                    jump: function (obj) {
                        var pageindex = obj.curr;
                        //layer.alert("点击了第" + pageindex + "页。");
                        //读取后台数据数据返回JSON后拼接HTML
                        load_blog_data(pageindex);
                    }
                });

            });

        });

    }


    /*删除*/
    function del(id) {
        layui.use('layer', function () {
            var layer = layui.layer;
            var $ = layui.jquery;

            layer.confirm('是否确认删除？', function () {

                var url = "/Adnn1n/Videomx/Delete?ids=" + id;
                pop_index = layer.load(0, {
                shade: [0.3, '#000'] //0.1透明度的白色背景
            });
                $.post(url, function (data) {
                layer.close(pop_index);
                    if (data.code == 0) {
                        layer.msg(data.msg, function () { location.reload(); });
                    } else {
                        layer.msg(data.msg);
                    }
                })

            })



        })


    }
</script>